home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / SpinLock.h,v < prev    next >
Text File  |  1989-02-23  |  3KB  |  207 lines

  1. head     3.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    grunwald:3.2; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 3.2
  10. date     89.02.20.15.37.43;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.1;
  13.  
  14. 3.1
  15. date     88.12.20.13.50.21;  author grunwald;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     88.10.30.13.06.11;  author grunwald;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     88.09.28.22.13.46;  author grunwald;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     88.09.21.20.51.47;  author grunwald;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     88.09.18.16.42.08;  author grunwald;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @@
  42.  
  43.  
  44. 3.2
  45. log
  46. @Start using Gnu library heaps for schedulers
  47. @
  48. text
  49. @// This may look like C code, but it is really -*- C++ -*-
  50. // 
  51. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  52. //
  53. // written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
  54. //
  55. #ifndef SpinLock_h
  56. #define SpinLock_h
  57.  
  58. //
  59. //    Implement a UNIX process spin-lock. While suitable for Threads,
  60. //    it's not clear it makes sense. Better to schedule another
  61. //    thread, typically.
  62. //
  63.  
  64. #include "assert.h"
  65. #include "Config.h"
  66.  
  67. static const char SpinLockFree = '\x00';
  68. static const char SpinLockHeld = '\xff';
  69.  
  70. class SpinLock {
  71.     int state;    // only a byte is used -- make alignment explicit
  72.     int pCount;
  73. public:
  74.     inline SpinLock();
  75.     inline ~SpinLock();
  76.     void reserve();
  77.     void release();
  78.     int count();
  79. };
  80.  
  81. inline
  82. SpinLock::SpinLock()
  83. {
  84.     state = SpinLockFree;
  85.     pCount = 0;
  86. }
  87.  
  88. inline
  89. SpinLock::~SpinLock()
  90. {
  91.     assert(state == SpinLockFree);
  92. }
  93.  
  94. #ifndef USE_SHARED_MEMORY
  95.   inline void
  96.   SpinLock::reserve()
  97.   {
  98.     assert(state == SpinLockFree);
  99.     state = ~SpinLockFree;
  100.   }
  101. #endif
  102.  
  103. inline void
  104. SpinLock::release()
  105. {
  106.     assert(state != SpinLockFree);
  107.     state = SpinLockFree;
  108. }
  109.  
  110. inline int
  111. SpinLock::count()
  112. {
  113.     return pCount;
  114. }
  115.  
  116. #endif
  117. @
  118.  
  119.  
  120. 3.1
  121. log
  122. @Steay version
  123. @
  124. text
  125. @@
  126.  
  127.  
  128. 1.4
  129. log
  130. @*** empty log message ***
  131. @
  132. text
  133. @@
  134.  
  135.  
  136. 1.3
  137. log
  138. @*** empty log message ***
  139. @
  140. text
  141. @d1 8
  142. a8 2
  143. #ifndef HardSpinLock_h
  144. #define HardSpinLock_h
  145. d17 1
  146. d19 2
  147. a20 2
  148. static const char HardSpinLockFree = '\x00';
  149. static const char HardSpinLockHeld = '\xff';
  150. d22 1
  151. a22 1
  152. class HardSpinLock {
  153. d26 2
  154. a27 2
  155.     inline HardSpinLock();
  156.     inline ~HardSpinLock();
  157. d34 1
  158. a34 1
  159. HardSpinLock::HardSpinLock()
  160. d36 1
  161. a36 1
  162.     state = HardSpinLockFree;
  163. d41 1
  164. a41 1
  165. HardSpinLock::~HardSpinLock()
  166. d43 1
  167. a43 1
  168.     assert(state == HardSpinLockFree);
  169. d46 9
  170. d56 1
  171. a56 1
  172. HardSpinLock::release()
  173. d58 2
  174. a59 2
  175.     assert(state != HardSpinLockFree);
  176.     state = HardSpinLockFree;
  177. d63 1
  178. a63 1
  179. HardSpinLock::count()
  180. @
  181.  
  182.  
  183. 1.2
  184. log
  185. @*** empty log message ***
  186. @
  187. text
  188. @d19 2
  189. a20 2
  190.     HardSpinLock();
  191.     ~HardSpinLock();
  192. @
  193.  
  194.  
  195. 1.1
  196. log
  197. @Initial revision
  198. @
  199. text
  200. @d16 1
  201. a16 1
  202.     char state;
  203. d42 1
  204. a42 1
  205.     assert(state == HardSpinLockHeld);
  206. @
  207.